//
//  GToastSuccess.swift
//  GOFM
//
//  Created by siri on 2024/1/25.
//  Copyright © 2024 Glad. All rights reserved.
//

import SwiftUI

struct GToastLoading<Content>: View where Content: View {

    @State private var rotationAngle: Double = 0.0
    @Binding var isShowing: Bool
    @Binding var text: String
    var content: () -> Content

    var body: some View {
        GeometryReader { _ in
            ZStack {
                
                VStack {
                    Spacer()
                    if !self.text.isEmpty {
                        Image(systemName: "rays")
                            .resizable()
                            .frame(width: 48, height: 48)
                            .padding(.top, 20)
                            .padding(.bottom, 20)
                            .rotationEffect(.degrees(rotationAngle))
                            .onAppear{
                                withAnimation(Animation.linear(duration: 1.0).repeatForever(autoreverses: false)){
                                    rotationAngle = 180.0
                                }
                            }
                        Text(self.text)
                            .padding(.top, -8)
                            .padding(.bottom, 16)
                    }
                }
                .frame(width: 120, height: 120, alignment: .center)
                .background(Color.g_color_bg_toast)
                .foregroundColor(Color.g_color_bg_white)
                .cornerRadius(CommonStyleSet.g_radius_medium)
                .opacity(self.isShowing ? 1 : 0)
                .padding(.horizontal, 135)
                .padding(.vertical, 320)
            }
        }
    }
}

struct GToastLoading_Previews: PreviewProvider {
    static var previews: some View {
        GToastLoading(isShowing: .constant(true), text: .constant("加载中")) { Text("") }
    }
}

